<?php
require_once $_SERVER['DOCUMENT_ROOT'] . '/accHestia/src/svr/com/acc_conn.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/accHestia/src/svr/com/rpc_com.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/accHestia/src/svr/com/fea/accMisc.php';

function make_sql_update_str(&$data, $tableName, $key) {
    $ret = "";
    $where = "";
    foreach ($data as $k => $v) {
        $spos = strpos($k, $tableName . "__");
        if(false === $spos) { //not exit tableName
            continue;
        }
        if(0 != $spos) { //not begin with tableName
            continue;
        }
        $filedName = substr($k, $spos + strlen($tableName . "__"));
        if($key == $filedName) {
            $where = " where " . $filedName . " = '" . $v . "'";
            continue;
        }
        $ret .= $filedName . " = '" . $v . "', ";;
    }
    $ret = preg_replace("/(.*), $/", "$1", $ret);
    $ret .= $where;
    return $ret;
}

function dorpc_accSet_save($data, &$res) {
    $pdb = new acc_DB();
    $ssql = "update account set " . make_sql_update_str($data, "account", "id") . ";";
    
    if(!($pdb->q($ssql))){
        set_res_NG($res, $ssql);
        return;
    }
    set_res_OK($res, $ssql);
}
?>

